from socket import *
from time import sleep, ctime

file = open("my.log",'a')
sock = socket()
sock.bind(('127.0.0.1',8888))
sock.listen(5)

sock.setblocking(False)

sock.settimeout(3)

while True:
    try:
        connfd, addr = sock.accept()
        print("Connect from ", addr)
    except timeout as e:
        msg = "%s : %s\n"%(ctime(),e)
        file.write(msg)
    except BlockingIOError as e:
        msg = "%s : %s\n"%(ctime(),e)
        file.write(msg)
        sleep(2)
    else:
        data = connfd.recv(1024)
        print(data.decode())